package com.example.maruko_course_backend.utils;

import com.example.maruko_course_backend.criterias.SentenceCriteria;
import com.example.maruko_course_backend.criterias.SentenceKnowledgeCriteria;
import com.example.maruko_course_backend.entity.Sentence;
import org.springframework.data.domain.ExampleMatcher;

public class ExampleUtil {

  public static final String LIKE = "like";

  public static Sentence createQueryExampleByCriteria(SentenceKnowledgeCriteria criteria) {
    Sentence example = new Sentence();
    example.setChapterNum(criteria.getChapterNum());
    example.setUpVideoNum(criteria.getVideoNum());
    example.setSentenceSeq(criteria.getSentenceSeq());
    return example;
  }

  public static Sentence createQueryExampleByCriteria(SentenceCriteria sentenceCriteria) {
    Sentence result = new Sentence();
    result.setUpVideoNum(sentenceCriteria.getVideoNum());
    result.setSentenceSeq(sentenceCriteria.getSentenceSeq());
    result.setSentenceOriginalStr(sentenceCriteria.getSentenceContentOrChinese());
    return result;
  }

  public static ExampleMatcher createExampleMatcher(String colName, String matchType) {
    if (LIKE.equals(matchType)) {
      return ExampleMatcher.matching().withMatcher(colName, ExampleMatcher.GenericPropertyMatchers.contains());
    }
    return null;
  }
}
